package com.jic.manager.impl;

import com.jic.common.base.vo.PageResult;
import com.jic.manager.mapper.SysProvinceCityMapper;
import com.jic.manager.entity.SysProvinceCity;
import com.jic.conf.request.SysProvinceCityRequest;
import com.jic.manager.service.SysProvinceCityService;
import com.jic.manager.utils.BeanUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;

/**
 * 省份城市表
 * @author : 
 * @email : 
 * @since : 2020-02-04 03:49:19
 * @version : v1.0.0
 */
@Service
public class SysProvinceCityServiceImpl implements SysProvinceCityService {

    @Autowired
    private SysProvinceCityMapper sysProvinceCityMapper;

    @Override
    public long insert(SysProvinceCity sysProvinceCity) {
        long flag = sysProvinceCityMapper.insert(sysProvinceCity);
        return flag;
    }

    @Override
    public long delete(Long id) {
        return sysProvinceCityMapper.delete(id);
    }

    @Override
    public long update(SysProvinceCity sysProvinceCity) {
        return sysProvinceCityMapper.update(sysProvinceCity);
    }

    @Override
    public SysProvinceCity queryByPrimaryKey(Long id){
        return sysProvinceCityMapper.queryByPrimaryKey(id);
    }

    @Override
    public List<SysProvinceCity> queryByLevel(Long level){
        return sysProvinceCityMapper.queryByLevel(level);
    }

    @Override
    public List<SysProvinceCity> queryAll(SysProvinceCity sysProvinceCity){
        return sysProvinceCityMapper.queryAll(sysProvinceCity);
    }

    @Override
    public PageResult<SysProvinceCity> queryPage(SysProvinceCityRequest sysProvinceCityRequest) throws Exception {
        SysProvinceCity sysProvinceCity = new SysProvinceCity();
        BeanUtils.Copy(sysProvinceCityRequest,sysProvinceCity);
        sysProvinceCity.setDeleteFlag(0);
        //计算下标
        int startIndex = (sysProvinceCityRequest.getStart() - 1) * sysProvinceCityRequest.getLimit();
        List<SysProvinceCity> list = sysProvinceCityMapper.queryPage(startIndex, sysProvinceCityRequest.getLimit(), sysProvinceCity);
        long count = sysProvinceCityMapper.queryPageCount(sysProvinceCity);
        PageResult pageResult = new PageResult();
        pageResult.setRows(list);
        pageResult.setTotal(count);
        return pageResult;
    }
}